import time
import multiprocessing
from concurrent.futures import ProcessPoolExecutor

def task(num):
    print("执行：",num)
    time.sleep(2)
    return num


def done(res):
    print(multiprocessing.current_process())
    time.sleep(1)
    print(res.result())
    time.sleep(1)

if __name__ == '__main__':
    pool = ProcessPoolExecutor(4)
    for i in range(50):
        fut = pool.submit(task, i)
        fut.add_done_callback(done)  # done的调用由主进程处理（与线程池不同）
    print(multiprocessing.current_process())
    pool.shutdown(True)


